package com.briup.day16;

import java.io.FileOutputStream;
import java.io.ObjectOutputStream;
import java.util.ArrayList;
import java.util.List;

/**
 * @author 谭梦寻
 * @version 1.1
 */
public class TestWriterList {

    public static void main(String[] args) throws Exception {
//1.实例化流对象
        ObjectOutputStream oos = new ObjectOutputStream(
                new
                        FileOutputStream("list.txt"));
//2.准备多个Student对象并加入List集合
        Student s1 = new Student(20, "tom");
        Student s2 = new Student(21, "zs");
        Student s3 = new Student(19, "jack");
        List<Student> list = new ArrayList<>();
        list.add(s1);
        list.add(s2);
        list.add(s3);
//3.将集合写入文件
        oos.writeObject(list);
        System.out.println("write list success!");
//4.操作完成后，关闭流
        oos.close();
    }
}

